<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2007, 2011. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../../../book.css" charset="ISO-8859-1" type="text/css">
<title>Force Return</title>
</head>
<body>
<h1> Force Return </h1>
<p> Select the <strong>Force Return </strong> command  to return from the current method with the specified value.</p>
<p>You can force an early return from a method (only 
  available when debugging on a Java SE 6 virtual machine). This returns 
  a value from the current stack frame without executing any more instructions 
  in the method and releases any locks obtained by synchronized blocks. 
  A return value is created by selecting an expression and <strong>Force 
  Return</strong> (<strong>Alt+Shift+F</strong>). This action is available 
  from the Java editor's context menu, top level <a href="../../../reference/menus/run/ref-menu-run.htm"><strong>Run</strong></a> menu, in the <a href="../../../reference/views/display/ref-debug_shell_view.htm"><strong>Display 
  View</strong></a>, and in the <strong><a href="../../../reference/views/shared/ref-detailpane.htm">detail pane</a></strong> of the <a href="../../../reference/views/variables/ref-variables_view.htm"><strong>Variables View</strong></a>.</p>
<p>Forcing an early return from a non-void method requires an expression 
  to be evaluated. For example, if a method was going to return false 
  you could return a value of true by selecting an expression in the <strong>Display 
  View</strong> and invoking <strong>Force Return</strong>. In the following example, <code>elementCount</code> is not equal to zero, and would return false 
  (see debug hover showing the value of <code>elementCount</code>).</p>
<p><img src="images/force-return-code.png" alt="Force Return Example"></p>
<p>From the<strong> Debug Shell View</strong>, we could enter the value we want returned, select it and use the <strong>Force Return</strong> command to force the method <code>isEmpty()</code> to return with that value (in the following example we will force <code>isEmpty()</code> to return with the value <code>true</code>). </p>
<p><img src="images/force-return-action.png" alt="Force Return Action in the Debug Shell View"></p>
<p>This command applies to:</p>
<ul>
  <li><a href="../../../concepts/concept-java-editor.htm"><strong>Java Editor</strong></a></li>
  <li><a href="../../../reference/views/display/ref-debug_shell_view.htm"><strong>Debug Shell View</strong></a></li>
  <li><a href="../../../reference/views/shared/ref-detailpane.htm"><strong>Detail Pane</strong></a> (in the <a href="../../../reference/views/expressions/ref-expressions_view.htm"><strong>Expressions View</strong></a> and <a href="../../../reference/views/variables/ref-variables_view.htm"><strong>Variables View</strong></a>)</li>
  <li><a href="../../../reference/menus/run/ref-menu-run.htm"><strong>Run Menu</strong></a></li>
</ul>
<h3 class="related">Related tasks</h3>
<a href="../../../tasks/task-evaluating_expressions.htm">Evaluating Expressions</a>
</body>
</html>
